package co.yixiang.yshop.module.product.controller.app.coupon;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
import co.yixiang.yshop.module.product.controller.admin.productcoupon.vo.CanvasProductCouponPageReqVO;
import co.yixiang.yshop.module.product.controller.admin.productcoupon.vo.CanvasProductCouponRespVO;
import co.yixiang.yshop.module.product.controller.app.coupon.vo.AppCouponDetailRespVO;
import co.yixiang.yshop.module.product.service.productcoupon.AppCouponService;
import co.yixiang.yshop.module.product.service.productcoupon.ProductCouponService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 商品优惠券")
@RestController
@RequestMapping("/product/coupon")
@Validated
public class AppCouponController {

    @Resource
    private AppCouponService appCouponService;

    @Resource
    private ProductCouponService couponService;


    @GetMapping("/receive-list/{productId}")
    @Operation(summary = "查询商品可领优惠券")
    @Parameter(name = "productId", description = "商品id", required = true, example = "1")
    public CommonResult<List<AppCouponDetailRespVO>> receiveList(@PathVariable Long productId) {
        return success(appCouponService.receiveList(productId, SecurityFrameworkUtils.getLoginUserId()));
    }

    @GetMapping("/list")
    @Operation(summary = "查询优惠券列表")
    public CommonResult<PageResult<CanvasProductCouponRespVO>> page(@Valid CanvasProductCouponPageReqVO pageReqVO) {
        return success(couponService.page(pageReqVO));
    }

}
